package com.pyue.eam.regi.controller;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pyue.eam.admin.api.entity.regi.CqRegiLibEntity;
import com.pyue.eam.common.core.util.R;
import com.pyue.eam.common.log.annotation.SysLog;
import com.pyue.eam.common.security.util.SecurityUtils;
import com.pyue.eam.regi.service.CqRegiLibService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.*;

/**
 * 团长表
 *
 * @author lucc
 * @date 2023-10-12 20:38:50
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/cqRegiLib")
@Tag(description = "cqRegiLib", name = "团长表管理")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class CqRegiLibController {
    private final CqRegiLibService cqRegiLibService;

    /**
     * 分页查询
     *
     * @param page      分页对象
     * @param cqRegiLib 团长表
     */
    @Operation(summary = "分页查询", description = "分页查询")
    @GetMapping("/page")
    // @PreAuthorize("@pms.hasPermission('eam_cqRegiLib_view')" )
    public R getCqRegiLibPage(@ParameterObject Page page, @ParameterObject CqRegiLibEntity cqRegiLib) {
        LambdaQueryWrapper<CqRegiLibEntity> wrapper = Wrappers.lambdaQuery(cqRegiLib);
        return R.ok(cqRegiLibService.page(page, wrapper));
    }


    /**
     * 通过id查询团长表
     *
     * @param regiId id
     * @return R
     */
    @Operation(summary = "通过id查询", description = "通过id查询")
    @GetMapping("/{regiId}")
    // @PreAuthorize("@pms.hasPermission('eam_cqRegiLib_view')" )
    public R getById(@PathVariable("regiId") Integer regiId) {
        return R.ok(cqRegiLibService.getById(regiId));
    }

    /**
     * 通过userId查询团长表
     */
    @Operation(summary = "通过userId查询团长表", description = "通过userId查询团长表")
    @GetMapping
    public R getByUserId() {
        return R.ok(cqRegiLibService.getRegiLibByUserId(SecurityUtils.getUserId()));
    }


    /**
     * 新增团长表
     *
     * @param cqRegiLib 团长表
     * @return R
     */
    @Operation(summary = "新增团长表", description = "新增团长表")
    @SysLog("新增团长表")
    @PostMapping
    // @PreAuthorize("@pms.hasPermission('eam_cqRegiLib_add')" )
    public R save(@RequestBody CqRegiLibEntity cqRegiLib) {
        return R.ok(cqRegiLibService.save(cqRegiLib));
    }

    /**
     * 修改团长表
     *
     * @param cqRegiLib 团长表
     * @return R
     */
    @Operation(summary = "修改团长表", description = "修改团长表")
    @SysLog("修改团长表")
    @PutMapping
    // @PreAuthorize("@pms.hasPermission('eam_cqRegiLib_edit')" )
    public R updateById(@RequestBody CqRegiLibEntity cqRegiLib) {
        return R.ok(cqRegiLibService.updateRegiInfo(cqRegiLib));
    }

    /**
     * 通过id删除团长表
     *
     * @param ids regiId列表
     * @return R
     */
    @Operation(summary = "通过id删除团长表", description = "通过id删除团长表")
    @SysLog("通过id删除团长表")
    @DeleteMapping
    // @PreAuthorize("@pms.hasPermission('eam_cqRegiLib_del')" )
    public R removeById(@RequestBody Integer[] ids) {
        return R.ok(cqRegiLibService.removeBatchByIds(CollUtil.toList(ids)));
    }


}

